using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class FilterHandler : LightRayHandler {

	public GameObject colorPicker;
	public GameObject colorIcon;
	
	public override void initialize(int id,Vector3 position, float rotation, Color c, bool fixedObj){
		Type = ObjectType.Filter;
		
		LevelConstants.nbFilter++;
		
		base.initialize(id, position, rotation, c, fixedObj);
		colorPicker.GetComponent<ColorPickerHandler>().colorObject(c);
		
		if(!isFixed){
			colorPicker.SetActive(true);
			colorIcon.SetActive(false);
		}
		
	}
	
	public override void onClick(){
		colorIcon.SetActive(false);
			
		colorPicker.SetActive(true);
	}
	
	public override List<LightHitInfo> getNextLightRay(LightHitInfo hitInfo){
		List<LightHitInfo> newRays = new List<LightHitInfo>();
		
		hitInfo.LightColor = ColorUtils.filterColor(hitInfo.LightColor,currentColor);
		
		if(hitInfo.LightColor == Color.black){
			hitInfo.Direction = Vector3.zero;	
		}
		
		newRays.Add(hitInfo);
		return newRays;	
	}
	
	public override void OnTriggerStay(Collider other){
		if(other.GetComponent<GhostCollideHandler>() != null){
			if(other.GetComponent<GhostCollideHandler>().type == Type && other.GetComponent<GhostCollideHandler>().color == this.currentColor){
				CorrectPosition = checkCorrectPosition(other.transform);
			}
		}
	}
	
	public void OnTriggerEnter(Collider other){
		if(other.GetComponent<GhostCollideHandler>() != null){
			if(other.GetComponent<GhostCollideHandler>().type == Type){
				colorPicker.GetComponent<ColorPickerHandler>().colorObject(other.GetComponent<GhostCollideHandler>().color);
			}
		}
	}
	
	void OnDestroy(){
		LevelConstants.nbFilter--;	
	}
	
}